<!-- src/components/DataButton.vue -->
<template>
    <div>
      <button @click="sendData">Send Data to Backend</button>
      <div v-if="response">
        <h3>Response from Backend:</h3>
        <pre>{{ response }}</pre>
      </div>
    </div>
  </template>
  
  <script>
  import axios from 'axios';
  
  export default {
    data() {
      return {
        response: null
      };
    },
    methods: {
      async sendData() {
        try {
          const dataToSend = { key: 'value' };
          // 打印发送的数据
          console.log("Sending data:", dataToSend);
          const response = await axios.post('http://localhost:5000/api/data', dataToSend);
          // 打印接收到的响应
          console.log("Received response:", response.data);
          this.response = response.data;
        } catch (error) {
          console.error('Error sending data:', error);
        }
      }
    }
  };
  </script>
  
  <style scoped>
  button {
    margin: 20px;
    padding: 10px 20px;
    font-size: 16px;
  }
  </style>
  